From b6d674623e0f8f4fa61e192b9f05bb846acc48fe Mon Sep 17 00:00:00 2001 From: Andrew Garrett Date: Thu, 11 Jan 2007 00:31:04 +0000 Subject: [PATCH] Fixes for a couple of embarrassing bugs I should have caught in testing. Brion and Tim save the day... --- includes/Article.php | 31 ++++++++++++++++++++++--------- includes/ProtectionForm.php | 2 +- includes/Title.php | 17 +++++++++-------- maintenance/updaters.inc | 1 - 4 files changed, 32 insertions(+), 19 deletions(-) diff --git a/includes/Article.php b/includes/Article.php index bf6127a030..2aa733d360 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -1649,7 +1649,7 @@ class Article { $updated = Article::flattenRestrictions( $limit ); $changed = ( $current != $updated ); - $changed = $changed || ($this->mTitle->getRestrictionCascadingFlags() != $cascade); + $changed = $changed || ($this->mTitle->areRestrictionsCascading() != $cascade); $protect = ( $updated != '' ); # If nothing's changed, do nothing @@ -2798,6 +2798,7 @@ class Article { /** * Add the primary page-view wikitext to the output buffer * Saves the text into the parser cache if possible. + * Updates templatelinks if it is out of date. * * @param string $text * @param Article $article @@ -2806,12 +2807,10 @@ class Article { public function outputWikiText( $text, $cache = true ) { global $wgParser, $wgUser, $wgOut; - $article = $this; - $popts = $wgOut->parserOptions(); $popts->setTidy(true); - $parserOutput = $wgParser->parse( $text, $article->mTitle, - $popts, true, true, $this->mRevisionId ); + $parserOutput = $wgParser->parse( $text, $this->mTitle, + $popts, true, true, $this->getRevIdFetched() ); $popts->setTidy(false); if ( $cache && $article && $parserOutput->getCacheTime() != -1 ) { $parserCache =& ParserCache::singleton(); @@ -2821,11 +2820,25 @@ class Article { if ( !wfReadOnly() ) { # Get templates from templatelinks - $tlTemplates_titles = $this->getUsedTemplates(); + $result = array(); + $id = $this->mTitle->getArticleID(); + + if( $id == 0 ) { + $tlTemplates = array(); + } - $tlTemplates = array (); - foreach( $tlTemplates_titles as $template_title) { - $tlTemplates[] = $template_title->getDBkey(); + $dbr =& wfGetDB( DB_SLAVE ); + $res = $dbr->select( array( 'templatelinks' ), + array( 'tl_namespace', 'tl_title' ), + array( 'tl_from' => $id ), + 'Article:getUsedTemplates' ); + + if ( false !== $res ) { + if ( $dbr->numRows( $res ) ) { + while ( $row = $dbr->fetchObject( $res ) ) { + $tlTemplates[] = $wgContLang->getNsText( $row->tl_namespace ) . ':' . $row->tl_title ; + } + } } # Get templates from parser output. diff --git a/includes/ProtectionForm.php b/includes/ProtectionForm.php index 53e2af30ce..1f71a1fdfd 100644 --- a/includes/ProtectionForm.php +++ b/includes/ProtectionForm.php @@ -39,7 +39,7 @@ class ProtectionForm { // but the db allows multiples separated by commas. $this->mRestrictions[$action] = implode( '', $this->mTitle->getRestrictions( $action ) ); } - $this->mCascade = $this->mTitle->getRestrictionCascadingFlags() & 1; + $this->mCascade = $this->mTitle->areRestrictionsCascading(); } // The form will be available in read-only to show levels. diff --git a/includes/Title.php b/includes/Title.php index 99cc45a58a..191d77e638 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -17,6 +17,9 @@ define ( 'GAID_FOR_UPDATE', 1 ); # reset the cache. define( 'MW_TITLECACHE_MAX', 1000 ); +# Constants for pr_cascade bitfield +define( 'CASCADE', 1 ); + /** * Title class * - Represents a title, which may contain an interwiki designation or namespace @@ -50,7 +53,7 @@ class Title { var $mArticleID; # Article ID, fetched from the link cache on demand var $mLatestID; # ID of most recent revision var $mRestrictions; # Array of groups allowed to edit this article - var $mCascadeRestrictionFlags; + var $mCascadeRestriction; var $mRestrictionsLoaded; # Boolean for initialisation on demand var $mPrefixedText; # Text form including namespace/interwiki, initialised on demand var $mDefaultNamespace; # Namespace index when there is no namespace @@ -1328,7 +1331,7 @@ class Title { function isCascadeProtectedImage() { global $wgEnableCascadingProtection; if (!$wgEnableCascadingProtection) - return; + return false; wfProfileIn(__METHOD__); @@ -1340,8 +1343,6 @@ class Title { $res = $dbr->select( $tables, $cols, $where_clauses, __METHOD__); - //die($dbr->numRows($res)); - if ($dbr->numRows($res)) { wfProfileOut(__METHOD__); return true; @@ -1360,7 +1361,7 @@ class Title { function isCascadeProtectedPage() { global $wgEnableCascadingProtection; if (!$wgEnableCascadingProtection) - return; + return false; wfProfileIn(__METHOD__); @@ -1381,12 +1382,12 @@ class Title { } } - function getRestrictionCascadingFlags() { + function areRestrictionsCascading() { if (!$this->mRestrictionsLoaded) { $this->loadRestrictions(); } - return $this->mCascadeRestrictionFlags; + return $this->mCascadeRestriction; } /** @@ -1411,7 +1412,7 @@ class Title { $this->mRestrictions[$row->pr_type] = explode( ',', trim( $row->pr_level ) ); - $this->mCascadeRestrictionFlags |= $row->pr_cascade; + $this->mCascadeRestriction |= $row->pr_cascade; } $this->mRestrictionsLoaded = true; diff --git a/maintenance/updaters.inc b/maintenance/updaters.inc index 9e6433f60d..1570a65500 100644 --- a/maintenance/updaters.inc +++ b/maintenance/updaters.inc @@ -37,7 +37,6 @@ $wgNewTables = array( array( 'filearchive', 'patch-filearchive.sql' ), array( 'redirect', 'patch-redirect.sql' ), array( 'querycachetwo', 'patch-querycachetwo.sql' ), -# array( 'page_restrictions', 'patch-page_restrictions.sql' ), ); $wgNewFields = array( -- 2.20.1